home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 2LQV49 (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  5.6 KB  |  203 lines

  1. package com.sun.java.swing;
  2.  
  3. import com.sun.java.swing.border.Border;
  4. import com.sun.java.swing.plaf.ComponentUI;
  5. import java.awt.Color;
  6. import java.awt.Font;
  7. import java.beans.PropertyChangeListener;
  8. import java.beans.PropertyChangeSupport;
  9. import java.lang.reflect.Method;
  10. import java.util.Hashtable;
  11.  
  12. public class UIDefaults extends Hashtable {
  13.    private static final Object PENDING = new String("Pending");
  14.    private PropertyChangeSupport changeSupport;
  15.    static Class class$com$sun$java$swing$JComponent;
  16.  
  17.    public UIDefaults() {
  18.    }
  19.  
  20.    public UIDefaults(Object[] keyValueList) {
  21.       super(keyValueList.length / 2);
  22.  
  23.       for(int i = 0; i < keyValueList.length; i += 2) {
  24.          super.put(keyValueList[i], keyValueList[i + 1]);
  25.       }
  26.  
  27.    }
  28.  
  29.    public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
  30.       if (this.changeSupport == null) {
  31.          this.changeSupport = new PropertyChangeSupport(this);
  32.       }
  33.  
  34.       this.changeSupport.addPropertyChangeListener(listener);
  35.    }
  36.  
  37.    protected void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
  38.       if (this.changeSupport != null) {
  39.          this.changeSupport.firePropertyChange(propertyName, oldValue, newValue);
  40.       }
  41.  
  42.    }
  43.  
  44.    public Object get(Object key) {
  45.       Object value = super.get(key);
  46.       if (value != PENDING && !(value instanceof ActiveValue) && !(value instanceof LazyValue)) {
  47.          return value;
  48.       } else {
  49.          synchronized(this) {
  50.             value = super.get(key);
  51.             if (value == PENDING) {
  52.                do {
  53.                   try {
  54.                      this.wait();
  55.                   } catch (InterruptedException var22) {
  56.                   }
  57.  
  58.                   value = super.get(key);
  59.                } while(value == PENDING);
  60.  
  61.                return value;
  62.             }
  63.  
  64.             if (value instanceof LazyValue) {
  65.                super.put(key, PENDING);
  66.             } else if (!(value instanceof ActiveValue)) {
  67.                return value;
  68.             }
  69.          }
  70.  
  71.          if (value instanceof LazyValue) {
  72.             try {
  73.                value = ((LazyValue)value).createValue(this);
  74.             } finally {
  75.                synchronized(this){}
  76.  
  77.                try {
  78.                   if (value == null) {
  79.                      super.remove(key);
  80.                   } else {
  81.                      super.put(key, value);
  82.                   }
  83.  
  84.                   this.notify();
  85.                } catch (Throwable var21) {
  86.                   throw var21;
  87.                }
  88.  
  89.             }
  90.          } else {
  91.             value = ((ActiveValue)value).createValue(this);
  92.          }
  93.  
  94.          return value;
  95.       }
  96.    }
  97.  
  98.    public Border getBorder(Object key) {
  99.       Object value = this.get(key);
  100.       return value instanceof Border ? (Border)value : null;
  101.    }
  102.  
  103.    public Color getColor(Object key) {
  104.       Object value = this.get(key);
  105.       return value instanceof Color ? (Color)value : null;
  106.    }
  107.  
  108.    public Font getFont(Object key) {
  109.       Object value = this.get(key);
  110.       return value instanceof Font ? (Font)value : null;
  111.    }
  112.  
  113.    public Icon getIcon(Object key) {
  114.       Object value = this.get(key);
  115.       return value instanceof Icon ? (Icon)value : null;
  116.    }
  117.  
  118.    public String getString(Object key) {
  119.       Object value = this.get(key);
  120.       return value instanceof String ? (String)value : null;
  121.    }
  122.  
  123.    public ComponentUI getUI(JComponent target) {
  124.       Class uiClass = this.getUIClass(target.getUIClassID());
  125.       Object uiObject = null;
  126.       if (uiClass == null) {
  127.          this.getUIError("no ComponentUI class for: " + target);
  128.       } else {
  129.          try {
  130.             Class var10000 = class$com$sun$java$swing$JComponent;
  131.             if (var10000 == null) {
  132.                try {
  133.                   var10000 = Class.forName("com.sun.java.swing.JComponent");
  134.                } catch (ClassNotFoundException var6) {
  135.                   throw new NoClassDefFoundError(((Throwable)var6).getMessage());
  136.                }
  137.  
  138.                class$com$sun$java$swing$JComponent = var10000;
  139.             }
  140.  
  141.             Class acClass = var10000;
  142.             Method m = uiClass.getMethod("createUI", acClass);
  143.             uiObject = m.invoke((Object)null, target);
  144.          } catch (NoSuchMethodException var7) {
  145.             this.getUIError("static createUI() method not found in " + uiClass);
  146.          } catch (Exception var8) {
  147.             this.getUIError("createUI() failed for " + target + " " + var8);
  148.          }
  149.       }
  150.  
  151.       return (ComponentUI)uiObject;
  152.    }
  153.  
  154.    public Class getUIClass(String uiClassID) {
  155.       Object className = this.get(uiClassID);
  156.  
  157.       try {
  158.          return className instanceof String ? Class.forName((String)className) : null;
  159.       } catch (ClassNotFoundException var3) {
  160.          return null;
  161.       }
  162.    }
  163.  
  164.    protected void getUIError(String msg) {
  165.       System.err.println("UIDefaults.getUI() failed: " + msg);
  166.  
  167.       try {
  168.          throw new Error();
  169.       } catch (Throwable var3) {
  170.          var3.printStackTrace();
  171.       }
  172.    }
  173.  
  174.    public Object put(Object key, Object value) {
  175.       Object oldValue = value == null ? super.remove(key) : super.put(key, value);
  176.       if (key instanceof String) {
  177.          this.firePropertyChange((String)key, oldValue, value);
  178.       }
  179.  
  180.       return oldValue;
  181.    }
  182.  
  183.    public void putDefaults(Object[] keyValueList) {
  184.       for(int i = 0; i < keyValueList.length; i += 2) {
  185.          Object value = keyValueList[i + 1];
  186.          if (value == null) {
  187.             super.remove(keyValueList[i]);
  188.          } else {
  189.             super.put(keyValueList[i], value);
  190.          }
  191.       }
  192.  
  193.       this.firePropertyChange("UIDefaults", (Object)null, (Object)null);
  194.    }
  195.  
  196.    public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
  197.       if (this.changeSupport != null) {
  198.          this.changeSupport.removePropertyChangeListener(listener);
  199.       }
  200.  
  201.    }
  202. }
  203.